package fr.cephb.socialsnp.core;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import fr.cephb.util.XObject;

@Entity
@Table(name="user2project")
public class User2Project 	extends XObject
implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;

@JoinColumn(name="user_id")
@ManyToOne(fetch = FetchType.LAZY)
private User user;

@JoinColumn(name="project_id")
@ManyToOne(fetch = FetchType.LAZY)
private Project project;

@Column(nullable=false,name="role")
@Enumerated(value=EnumType.STRING)
private Role role=Role.ANONYMOUS;

public long getId() {
	return id;
}

private void setId(long id) {
	this.id = id;
}

public User getUser() {
	return user;
}

public void setUser(User user) {
	this.user = user;
}

public Project getProject() {
	return project;
}

public void setProject(Project project) {
	this.project = project;
}

public Role getRole() {
	return role;
}

public void setRole(Role role) {
	this.role = role;
}

@Override
public int hashCode() {
	final int prime = 31;
	int result = super.hashCode();
	result = prime * result + (int) (id ^ (id >>> 32));
	return result;
	}


@Override
public String toString() {
	return getId()+":"+ getUser()+" -- "+ getProject()+" : "+getRole();
	}


}
